<cfscript>
	scholarshipGateway = new assets.calgrants.com.gateway.ScholarshipGateway();
	if (IsUserLoggedIn()) {
		scholarship = scholarshipGateway.get(Scholarship_ID = GetAuthUser());
	} else if (IsDefined("Claim_ID") and Len(Trim(Claim_ID)) gt 0) {
		qScholarship = scholarshipGateway.query(Claim_ID = Claim_ID);
		scholarship = scholarshipGateway.get(Scholarship_ID = qScholarship.Scholarship_ID);
	}
</cfscript>

<cfif IsDefined("scholarship") and IsNumeric(scholarship.getScholarship_ID())>
	
	<cfoutput>
		<script src="#request.pathToJQueryTubeplayer#" type="text/javascript"></script>
	</cfoutput>	
	
	<script type="text/javascript">
		<cfoutput>
			var claimID = "#scholarship.getClaim_ID()#";
			var orientationCompleted = #scholarship.getOrientation_Completed()#;
		</cfoutput>
		var playerDefaults = {
			// Plugin init params
			width: 800, // the width of the player
			height: 500, // the height of the player
			allowFullScreen: true, // true by default, allow user to go full screen
			initialVideo: "sAJUBxIcM34", // the video that is loaded into the player
			start: 9, 
			preferredQuality: "default",// preferred quality: default, small, medium, large, hd720
			showControls: orientationCompleted == 1 ? true : false, // whether the player should have the controls visible, 0 or 1
			showRelated: 0, // show the related videos when the player ends, 0 or 1 
			autoPlay: false, // whether the player should autoplay the video, 0 or 1
			autoHide: true, 
			theme: "light", // possible options: "dark" or "light"
			color: "red", // possible options: "red" or "white"
			showinfo: false, // if you want the player to include details about the video
			modestbranding: true, // specify to include/exclude the YouTube watermark
			protocol: "https",
			// the location to the swfobject import for the flash player, default to Google's CDN
			wmode: "transparent", // note: transparent maintains z-index, but disables GPU acceleration
			swfobjectURL: "ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js",
			loadSWFObject: true, // if you include swfobject, set to false
			// HTML5 specific attrs
			iframed: false, // iframed can be: true, false; if true, but not supported, degrades to flash
			// Player Trigger Specific Functionality
			onPlayerEnded: function() {
				$("#pauseButtonContainer").hide();
				$("#playButtonContainer").hide();
				$("#orientationVideoContainer").hide();
				$("#loggingContainer").show();
				logScholarOrientationCompleted();
			},
			onPlayerPlaying: function() {
				$("#playButtonContainer").hide();
				$("#pauseButtonContainer").show();
			},
			onPlayerPaused: function() {
				$("#pauseButtonContainer").hide();
				$("#playButtonContainer").show();
			},
			onErrorNotEmbeddable: function() {
				$("#pauseButtonContainer").hide();
				$("#playButtonContainer").hide();
				$("#loggingContainer").hide();
				$("#orientationVideoContainer").hide();
				$("#playerNotEmbedableContainer").show();
				$("#claimButtonsContainer").show();
			}
		};
	
		var logScholarOrientationCompleted = function() {
			$.ajax({
				type: "POST",
				url: "/assets/calgrants/com/API.cfc?method=logScholarOrientationCompleted",
				data: {Claim_ID: claimID},
				dataType: "json",
				success: function(data){
					redirectPage();
				},
				error: function(jqXHR, textStatus, errorThrown){
					//console.log(errorThrown);
				}
			});	
		}
		var redirectPage = function() {
			location.href = pbsOrientationRedirectURL + claimID;
		}
		var playOrientationVideo = function() {
			$("#orientationVideoContainer").tubeplayer("play");
		}
		var pauseOrientationVideo = function() {
			$("#orientationVideoContainer").tubeplayer("pause");
		}
		$(function() {
			$("#orientationVideoContainer").tubeplayer(playerDefaults);
			$("#playButtonContainer").show();
			if (orientationCompleted == 1) {
				$("#claimButtonsContainer").show();
			} else {
				$("#claimButtonsContainer").hide();
			}
		});
	</script>
	
	<cfoutput>

		<div class="container-fluid">
			<div class="row-fluid">
				<div class="span12">
					<cfif NOT scholarship.getOrientation_Completed() and NOT IsUserLoggedIn()>
						<p>Please watch the 30 minute orientation video. Completing an orientation is required for you to recieve the Performance Based Scholarship. Once you complete this orientation, the rest of the claiming process should take about 10 minutes to complete.</p>
						<p>After the video has finished you will be forward to the next step in claiming your scholarship. <strong>Allow the video to run to the end and do not refresh this page, otherwise you may not receive credit for completing the orientation.</strong>  It is ok to pause the video, however it must run to the end for you to receive credit.  If you have to leave before the orientation is finished, pause the video and leave this browser window open.  When you return you will be able to play the video from the point you left.  If you close the browser before the video ends, you will have to start from the beginning.  Fast forward is not available.</p>
					<cfelseif scholarship.getOrientation_Completed() and NOT IsUserLoggedIn()>
						<p>You have completed the orientation requirement for your scholarship.</p>
						<p>If you would like to skip the orientation video, click the Continue button below.</p>
					</cfif>
					<br />
					<center>
						<div id="playButtonContainer" class="clearfix" style="width: 800px; margin-bottom: 4px; display: none;">
							<a id="playButton" href="##" class="btn btn-primary btn-large btn-block" onclick="playOrientationVideo(); return false;"><i class="icon-play icon-white"></i> Play Orientation Video</a>
						</div>
						<div id="pauseButtonContainer" class="clearfix" style="width: 800px; margin-bottom: 4px; display: none;">
							<a id="pauseButton" href="##" class="btn btn-primary btn-large btn-block" onclick="pauseOrientationVideo(); return false;"><i class="icon-pause icon-white"></i> Pause Orientation Video</a>
						</div>		
						<div id="orientationVideoContainer" class="clearfix" style="width: 800px;"></div>
						<div id="loggingContainer" class="alert alert-success clearfix" style="width: 800px; display: none; text-align: left;">
							<p><strong>Please Wait</strong></p>
							<p>Your scholarship account is being updated to give you credit for completing the orientation.</p>
							<p>In a moment you will be forwarded to the next step in claiming your scholarship.</p>
						</div>
						<div id="playerNotEmbedableContainer" class="alert alert-error clearfix" style="width: 800px; display: none; text-align: left;">
							<p><strong>Error Loading Orientation Video</strong></p>
							<p>The device or browser you are using is not compatible with the orientation video.</p>
							<p>Please contact us at <a href="mailto:#request.personality.email#">#request.personality.email#</a> right away.</p>
						</div>
					</center>
				</div>
			</div>
			<cfif NOT IsUserLoggedIn()>
				<div id="claimButtonsContainer" class="row-fluid">
					<div class="span12">
						<span class="pull-right">
							<a href="?view=scholarWelcome&Claim_ID=#Claim_ID#" class="btn btn-primary">Back</a>
							<a href="?view=editScholarProfile&Claim_ID=#Claim_ID#" class="btn btn-primary">Continue</a>
						</span>
					</div>
				</div>
			</cfif>
		</div>

	</cfoutput>

<cfelse>

	<div class="alert alert-info notFound">Scholarship not found</div>

</cfif>